{% extends 'base/base_table.html' %}
{% load tags %}

{% block title %}ITAdmin | 批量处理(SlatSaltStack){% endblock %}

{% block css %}
    <link href="/static/css/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <link href="/static/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
{% endblock %}


{% block table_thead %}
<tr>
    <th  style="text-align: center;vertical-align: middle">minion ID</th>
    <th  style="text-align: center;vertical-align: middle">状态</th>
    <th  style="text-align: center;vertical-align: middle">操作</th>
</tr>
{% endblock %}


{% block table_bady %}
    {% for object in objects %}
        <tr>
            <td style="text-align: center;vertical-align: middle">{{ object.id }}</td>
            {% if object.online == 1 %}
                <td style="text-align: center;vertical-align: middle">
                    <span class="label label-sm label-success">管理中</span>
                </td>
                <td style="text-align: center;vertical-align: middle">
                    <button class="btn btn-sm btn-danger" id="delserver_{{ object.id }}" value="{{ object.id }}"><strong>移除管理</strong></button>
                </td>
            {% else %}
                <td style="text-align: center;vertical-align: middle">
                    <span class="label label-sm label-error">非管理中</span>
                </td>
                <td style="text-align: center;vertical-align: middle">
                    <button class="btn btn-sm btn-primary" id="addserver_{{ object.id }}" value="{{ object.id }}"><strong>添加管理</strong></button>
                </td>
            {% endif %}
        </tr>
    {% endfor %}
{% endblock %}

{% block base_script %}
    <script src="/static/js/plugins/sweetalert/sweetalert.min.js"></script>
    <script src="/static/js/plugins/datapicker/bootstrap-datepicker.js"></script>
{% endblock %}

{% block script %}
<script>
    $(document).ready(function() {

        $('#date_added').datepicker({
            todayBtn: "linked",
            keyboardNavigation: false,
            forceParse: false,
            calendarWeeks: true,
            autoclose: true
        });

        $('#date_modified').datepicker({
            todayBtn: "linked",
            keyboardNavigation: false,
            forceParse: false,
            calendarWeeks: true,
            autoclose: true
        });

    });
</script>
<script type="text/javascript">
    $(function () {

        $("button[id^='delserver_']").click(function () {
            var minio_id = $(this).attr("value")
            swal({
                    title: "确定删除?",
                    text: "您是否确定要删除所选的服务器!",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    closeOnConfirm: false
                    }, function () {
                         $.post('{% url "saltminions" %}', {id:minio_id, method: 'del'}, function (data) {
                            if (data.status) {
                                swal({title:"成功!", text:"删除服务器成功", type:"success"},function () {
                                    location.href = "{% get_url request %}"
                                });
                            } else {
                                swal("失败!", "未能删除服务器", "error");
                            }
                        },'json');

            });

        });

        $("button[id^='addserver_']").click(function () {
            $.post('{% url "saltminions" %}', {id:$(this).attr("value"), method: 'add'}, function (data) {
                if (data.status) {
                    swal({title:"成功!", text:"添加服务器成功", type:"success"},function () {
                        location.href = "{% get_url request %}"
                    });
                } else {
                    swal("失败!", "未能添加服务器", "error");
                }
            },'json');
        });

        $('#pages').val('{{ entry }}')
        $('#pages').change(function () {
            var search = '{{ search }}'
            if (search == '') {
                location.href = "{% url 'saltminions' %}?page={{ num }}&entry=" + $(this).val();
            } else {
                location.href = "{% url 'saltminions' %}?page={{ num }}&{{ search }}&entry=" + $(this).val();
            }
        });
    });
</script>
{% endblock %}